"""
@File         : validate.py
@Time         : 2024/05/06 15:56:17
@Author       : Qrj
@Email        : 923207736@qq.com
@Description  : 站内信记录的验证模型
"""

from datetime import datetime

from pydantic import BaseModel, Field, conint

from src.business.admin.system.station_message.enums import (
    StationMessageTypeEnum,
)
from src.schemas.validate import (
    BaseSearchValidateSchemaMixin,
    BaseValidateSchemaConfigMixin,
)


class StationMessageRecordCreateValidateSchema(
    BaseModel, BaseValidateSchemaConfigMixin
):
    """用于创建站内信记录的验证模型"""

    template_id: int = Field(default=..., ge=1, description="模板ID")
    template_params: dict[str, str] = Field(
        default_factory=dict, description="模板参数"
    )
    receiver_ids: list[conint(ge=1)] = Field(
        default=..., min_length=1, description="接收者ID"
    )


class StationMessageRecordSelfUpdateReadStatusValidateSchema(
    BaseModel, BaseValidateSchemaConfigMixin
):
    """用于修改用户自身站内信记录的已读状态验证模型"""

    ids: list[conint(ge=1)] = Field(
        default=..., min_length=1, description="需修改的主键列表"
    )
    read_status: bool = Field(default=..., description="是否已读")


class StationMessageRecordDeleteValidateSchema(
    BaseModel, BaseValidateSchemaConfigMixin
):
    """用于删除站内信记录的验证模型"""

    ids: list[conint(ge=1)] = Field(
        default=..., min_length=1, description="需删除的主键列表"
    )


class StationMessageRecordListSearchValidateSchema(
    BaseModel, BaseSearchValidateSchemaMixin
):
    """用于查询站内信记录列表的验证模型"""

    content: str | None = Field(
        default=None, min_length=1, max_length=2048, description="消息内容"
    )
    type: StationMessageTypeEnum | None = Field(default=None, description="消息类型")
    sending_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="发送时间",
        json_schema_extra={"allow_order": True},
    )
    sender_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="发送者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    receiver_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="接收者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    read_status: bool | None = Field(default=None, description="是否已读")
    read_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="查看时间",
        json_schema_extra={"allow_order": True},
    )
    template_name: str | None = Field(
        default=None,
        min_length=1,
        max_length=50,
        description="模板名称",
        json_schema_extra={"str_like_search_type": "complete"},
    )
